#! /usr/bin/env python
# Copyright (C) 2010 Samuel Mehrbrodt
#
# Recordman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import gtk
import pango
import gobject

#projectlist = None

class ProjectList(gtk.TreeView):
    '''
    Manage the presentation list.
    '''
    
    def __init__(self):
        gtk.TreeView.__init__(self)
        self.set_size_request(150, 250)
        
        date = gtk.CellRendererText()
        #date.set_property("ellipsize", pango.ELLIPSIZE_END)
        column = gtk.TreeViewColumn("Date")
        column.set_resizable(True)
        column.pack_start(date, False)
        column.set_cell_data_func(date, self._get_row_date)
        self.append_column(column)
        
        name = gtk.CellRendererText()
        column = gtk.TreeViewColumn("Name")
        column.set_resizable(True)
        column.pack_start(name, False)
        column.set_cell_data_func(name, self._get_row_name)
        self.append_column(column)
        self.set_headers_clickable(False)
        self.get_selection().connect("changed", self._on_project_activate)
        self.set_model(gtk.ListStore(gobject.TYPE_PYOBJECT))
    
        archive = gtk.CellRendererText()
        column = gtk.TreeViewColumn("mp3")
        column.set_resizable(True)
        column.pack_start(name, False)
        column.set_cell_data_func(name, self._get_row_name)
        self.append_column(column)
        self.set_headers_clickable(False)
        self.get_selection().connect("changed", self._on_project_activate)
        self.set_model(gtk.ListStore(gobject.TYPE_PYOBJECT))
        
        original = gtk.CellRendererText()
        column = gtk.TreeViewColumn("wav")
        column.set_resizable(True)
        column.pack_start(name, False)
        column.set_cell_data_func(name, self._get_row_name)
        self.append_column(column)
        self.set_headers_clickable(False)
        self.get_selection().connect("changed", self._on_project_activate)
        self.set_model(gtk.ListStore(gobject.TYPE_PYOBJECT))
        
    def _on_project_activate(self, *args):
        ''
        pass
    
    def _get_row_date(self, column, cell, model, titer):
        'Returns the date of the current sermon.'
        pres = model.get_value(titer, 0)
        cell.set_property('text', pres.get_datum())
    
    def _get_row_name(self, column, cell, model, titer):
        'Returns the preacher name of the current sermon.'
        pres = model.get_value(titer, 0)
        cell.set_property('text', pres.get_name())
